from typing import Optional
from fastapi import FastAPI
import os

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"item_id": item_id, "q": q} # q:null


@app.get("/hook")
def hook():
    try:
        os.system('npm init -y')
        os.system('git add .')
        os.system('git commit -m "system commit"')
        return {"code": 20000, "msg": "success"}
    except:
        return {"code": -20001, "msg": "git shell exec error!"}
